var config = require('../../../config.js');
var request = require('../../../utils/request.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    size: 10,
    activitylist: [],
    hasMore: true,
  },

  onShow:function(){
    this.getActivityLstAction();
  },


  onPullDownRefresh:function(){
    wx.showNavigationBarLoading();
    this.getActivityLstAction();
  },


  getActivityLstAction: function () {
    var params = {
      page: this.data.page,
      size :this.data.size
    }
    var url = config.activityLstUrl;
    request.requestPost(url, params)
      .then(data => {

        //隐藏顶部loading
        wx.hideNavigationBarLoading();
        // 停止下拉动作  
        wx.stopPullDownRefresh();

        let lst = this.data.activitylist;
        if (this.data.page == 1) {
          lst = data;
        }else{
          data.map(item => {
            lst.push(item);
          });
        }
        this.setData({
          activitylist : data,
          hasMore: data.length == this.data.size,
        });

       

      }).catch(msg => {
        console.log(msg);
        //隐藏顶部loading
        wx.hideNavigationBarLoading();
        // 停止下拉动作  
        wx.stopPullDownRefresh();
      });
  },


  // 加载更多
  loadMoreAction: function () {
    var index = this.data.page;
    index = index + 1;
    this.setData({
      page: index
    })
    this.getActivityLstAction();
  },

//跳转活动详情
  onActivityDetailClick:function(event){
    let id = event.currentTarget.dataset.id;
    console.log(event);
    wx.navigateTo({
      url: '../detail/activitydetail?id='  + id,
    });
  }

})